<template>
  <h3>getters</h3>
  <div>这是child2组件 - {{ num }}</div>
  <div>msg: {{ msg }}</div>
  <div>timeStr: {{ timeStr }}</div>
  <div>count2: {{ count2 }}</div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  computed: {
    num() {
      return this.$store.state.count;
    },
    msg() {
      return this.$store.state.message.split("").reverse().join("");
    },

    // ...mapGetters(["timeStr"]),
    ...mapGetters({
      timeStr: "timeStr",
    }),

    // timeStr() {
    //   return this.$store.getters.timeStr;
    // },
    count2() {
      return this.$store.getters.count2(5);
    },

    // time() {
    //   var date = new Date(this.$store.state.time);
    //   var Y = date.getFullYear() + "-";
    //   var M =
    //     (date.getMonth() + 1 < 10
    //       ? "0" + (date.getMonth() + 1)
    //       : date.getMonth() + 1) + "-";
    //   var D =
    //     (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
    //   var h =
    //     (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
    //   var m =
    //     (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
    //     ":";
    //   var s =
    //     date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    //   return Y + M + D + h + m + s;
    // },
  },
};
</script>
